﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using com.dz.common;
using com.dz.components;
namespace com.dz.web
{
    public partial class Register : BasePage
    {
        const string c_top_template = "<DIV class=bd><DIV class=toplist><DIV class=list12><table cellpadding=\"0\" cellspacing=\"0\">{0}</table></div></div></div>";

        const string c_top__item_template = "<tr><td class=\"book\"><A href=\"/{0}.aspx\" target=_blank>{1}</A></td><td class=\"click\">{2}</td></tr>";

        public string m_return_url = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            m_return_url = Request["ReturnUrl"];

            if (string.IsNullOrEmpty(m_return_url))
            {
                if (Request.UrlReferrer != null)
                {
                    m_return_url = Request.UrlReferrer.ToString();
                    if (string.IsNullOrEmpty(m_return_url))
                        m_return_url = "/default.aspx";
                }
            }
            if (!string.IsNullOrEmpty(m_return_url))
            {
                if ((m_return_url.ToLower().StartsWith("http") || m_return_url.ToLower().StartsWith("https") || m_return_url.ToLower().StartsWith("ftp")))
                {
                    m_return_url = "/default.aspx";
                }
            }
            BindTopBook();
        }

        private void BindTopBook()
        {
            BookManager m_book_mgr = new BookManager();
            StringBuilder sb = new StringBuilder();
            try
            {
                DataSet ds = m_book_mgr.GetClickBookList(12);
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int index = 0; index < ds.Tables[0].Rows.Count; index++)
                    {
                        sb.AppendFormat(c_top__item_template, ds.Tables[0].Rows[index]["bookId"], SystemUtil.GetGBString(ds.Tables[0].Rows[index]["bookName"].ToString(), 14), ds.Tables[0].Rows[index]["click"]);
                    }
                    lblTopClick.Text = string.Format(c_top_template, sb.ToString());
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取热门作品失败" + ex.ToString());
            }
        }
    }
}
